package com.xuecheng.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.media.model.po.MediaProcess;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author itcast
 */
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {
    /**
     * 查询应该执行的任务
     * @param shardTotal 任务执行器总数
     * @param shardIndex 任务执行器序号
     * @param count 执行任务条数
     * @return
     */
  @Select("select * from media_process where id % #{shardTotal}=#{shardIndex} and  " +
          "(status = '1' or  '3') and fail_count < 3 limit #{count}")
    public List<MediaProcess> selectListByShardIndex(@Param("shardTotal") int shardTotal,
@Param("shardIndex") int shardIndex, @Param("count") int count         );


    /**
     * 开启执行任务
     * @param id
     * @return
     */
  @Update("update media_process set status='4' where status='1' or status ='3' and fail_count < 3 and " +
          "id = #{id}")
  int startTask(@Param("id") Long id);
}
